<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择材料入库单明细信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'checkbox';
    }else{
        choose_type = 'radio';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');
    var parent_enginid = getQueryVariable('enginid') || 0;
    var parent_caiid = getQueryVariable('caiid') || 0;
    var parent_type = getQueryVariable('type') || 0;
    var parent_gonger = getQueryVariable('gonger') || '';
    parent_gonger = decodeURI(parent_gonger);

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;
        $("#search_table").hide();
        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_stuff_ru_list_pagejie),where: {
                enginid:parent_enginid,
                caiid:parent_caiid,
                type:parent_type,
                gonger:parent_gonger,
            }, page: false, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){
                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data
                };
            }
            ,cols: [[
                {type:choose_type}
                ,{field: 'name', title: '物资名称及规格'}
                ,{field: 'unit', title: '单位'}
                ,{field: 'price', title: '单价'}
                ,{field: 'num', title: '入库数量'}
                ,{field: 'money', title: '入库金额'}
                ,{field: 'dt', title: '入库日期'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'stuff_jie'){
                var str = '';
                var nums = $("#jie_list tr", parent.document).length;
                for (var key in data){
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td>';
                    str += '<input type="text" onclick="choose_stuff_ru_list_pagejie_one(this)" listid="'+data[key].id+'" readonly value="'+data[key].name+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" disabled class="layui-input unit disabled" value="'+data[key].unit+'"></td>';
                    str += '<td><input type="text" disabled class="layui-input price disabled" value="'+data[key].price+'"></td>';
                    str += '<td><input type="text" disabled class="layui-input num disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="text" disabled class="layui-input money disabled" value="'+data[key].money+'"></td>';
                    str += '<td><input type="text" disabled class="layui-input dt disabled" value="'+data[key].dt+'"></td>';
                    str += '<td><input type="text" disabled class="layui-input jienum disabled" value="'+data[key].num+'"></td>';
                    str += '<td><input type="number" class="layui-input jiemoney" value="'+data[key].money+'"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                }
                $("#jie_list", parent.document).append(str);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'stuff_jie_one'){
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.name').val(data[0].name).attr('listid',data[0].id);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.unit').val(data[0].unit);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.price').val(data[0].price);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.num').val(data[0].num);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.money').val(data[0].money);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.dt').val(data[0].dt);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.jienum').val(data[0].num);
                $("#jie_list tr", parent.document).eq(parent_domkey).find('.jiemoney').val(data[0].money);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else{

            }


            layer_close();
        });

    });
</script>
</body>
</html>
